#include "etcd.hpp"
#include "channel.hpp"
#include "user.pb.h"
#include "utils.hpp"
#include <gtest/gtest.h>
DEFINE_bool(run_mode, false, "程序的运行模式, false-调试； true-发布；");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(etcd_host, "http://127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(user_service, "/service/user_service", "关注的服务名称");
ServiceChannel::ChannelPtr channel;

int main(int argc, char* argv[]) {
    init_logger(FLAGS_log_file, int_log_level_map(FLAGS_log_level), FLAGS_run_mode);
    testing::InitGoogleTest();
    ServiceManager::ptr service_manager = std::make_shared<ServiceManager>();
    service_manager->declared(FLAGS_user_service);
    auto put_cb = std::bind(&ServiceManager::onServiceOnline, service_manager.get(), std::placeholders::_1, std::placeholders::_2);
    auto del_cb = std::bind(&ServiceManager::onServiceOffline, service_manager.get(), std::placeholders::_1, std::placeholders::_2);
    Discovery::ptr dclient = std::make_shared<Discovery>(FLAGS_etcd_host, FLAGS_base_service, put_cb, del_cb);
    //获取用户服务信道管理对象
    auto channel_manager = service_manager->choose(FLAGS_user_service);
    if(channel_manager == nullptr) {
        LOG_DEBUG("获取文件服务信道失败");
        return -1;
    }
    // 获取用户服务信道
    channel = channel_manager->choose();
    if(channel == nullptr) {
        LOG_DEBUG("获取用户服务信道失败");
        return -1;
    }

    
    return 0;
}